﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Aspose.Cells;
using System.Web;
using System.Data;
using Aspose.Words;

namespace hrainwebbase.CommonTools
{
    public class AsposeWord
    {
        public static string WordToPdf(string p)
        {
            //读取doc文档 c可以合并多个
            //Document doc = new Document(lbWord.GetItemText(lbWord.Items[0]));
            //doc.RemoveAllChildren();

            //string[] filepath = new string[lbWord.Items.Count];
            //for (int i = 0; i < filepath.Length; i++)
            //{
            //    filepath[i] = lbWord.GetItemText(lbWord.Items[i]);
            //    Document srcDoc = new Document(filepath[i]);
            //    doc.AppendDocument(srcDoc, ImportFormatMode.UseDestinationStyles);
            //}
            //doc.Save(savePath, SaveFormat.Pdf);

            Document doc = new Document(@"D:\model5.doc");

            //保存为PDF文件，此处的SaveFormat支持很多种格式，如图片，epub,rtf 等等

            doc.Save("D:\\temp.pdf", SaveFormat.Pdf);
            return
                "";
        }

        //for (int di = 0; di < docall; di++)
        //        {
        //            rows = di * 多少行;

        //            Aspose.Words.Document doc;

        //            string str = System.Windows.Forms.Application.StartupPath;

        //            doc = new Aspose.Words.Document(str + "\\model\\model5.doc"); //载入模板 



        //            //单据信息
        //            if (doc.Range.Bookmarks["经手人"] != null)
        //            {
        //                Aspose.Words.Bookmark mark = doc.Range.Bookmarks["经手人"];
        //                mark.Text = order_info.承运人;
        //            }
        //            if (doc.Range.Bookmarks["制表人"] != null)
        //            {
        //                Aspose.Words.Bookmark mark = doc.Range.Bookmarks["制表人"];
        //                mark.Text = order_info.操作员;
        //            }
        //            if (doc.Range.Bookmarks["送货人"] != null)
        //            {
        //                Aspose.Words.Bookmark mark = doc.Range.Bookmarks["送货人"];
        //                mark.Text = order_info.发货验证人;
        //            }

        //            if (doc.Range.Bookmarks["收货单位"] != null)
        //            {
        //                Aspose.Words.Bookmark mark = doc.Range.Bookmarks["收货单位"];
        //                mark.Text = usreinfo.name + "          ";
        //            }
        //            if (doc.Range.Bookmarks["收地址"] != null)
        //            {
        //                Aspose.Words.Bookmark mark = doc.Range.Bookmarks["收地址"];
        //                mark.Text = usreinfo.where_user + " ";
        //            }
        //            if (doc.Range.Bookmarks["收人"] != null)
        //            {
        //                Aspose.Words.Bookmark mark = doc.Range.Bookmarks["收人"];
        //                mark.Text = usreinfo.person_name + "          ";
        //            }
        //            if (doc.Range.Bookmarks["收电话"] != null)
        //            {
        //                Aspose.Words.Bookmark mark = doc.Range.Bookmarks["收电话"];
        //                mark.Text = usreinfo.tel + "          ";
        //            }
        //            doc.Range.Bookmarks["备注"].Text = order_info.备注;
        //            doc.Range.Bookmarks["年"].Text = dtDate.DateTime.Year.ToString();
        //            doc.Range.Bookmarks["月"].Text = dtDate.DateTime.Month.ToString();
        //            doc.Range.Bookmarks["日"].Text = dtDate.DateTime.Day.ToString();
        //            //if (new JCCheck().hasjc())
        //            //{
        //            //    doc.Range.Bookmarks["单号"].Text = "单号";// order_info.order_id;
        //            //}
        //            //else
        //            //{ doc.Range.Bookmarks["单号"].Text = "测试版本"; }
        //            doc.Range.Bookmarks["单号"].Text = order_info.order_id;
        //            double payall = 0;
        //            //产品信息

        //            int nowi = 0;
        //            for (int i = rows; nowi < 多少行 && pn < all; i++)
        //            {
        //                pn++;
        //                nowi++;
        //                //仓库名称,产品名称,单位,单价,金额,数量
        //                //仓库名称,产品名称,单位,单价,金额,数量,仓库ID,产品ID
        //                doc.Range.Bookmarks["型号" + nowi].Text = dataGridView2.Rows[i].Cells["产品名称"].Value.ToString();

        //                doc.Range.Bookmarks["单位" + nowi].Text = dataGridView2.Rows[i].Cells["单位"].Value.ToString();
        //                doc.Range.Bookmarks["单价" + nowi].Text = "￥" + double.Parse(dataGridView2.Rows[i].Cells["单价"].Value.ToString()).ToString("F2");
        //                doc.Range.Bookmarks["数量" + nowi].Text = dataGridView2.Rows[i].Cells["数量"].Value.ToString();
        //                doc.Range.Bookmarks["金额" + nowi].Text = "￥" + double.Parse(dataGridView2.Rows[i].Cells["金额"].Value.ToString()).ToString("F2");
        //                payall += (double)dataGridView2.Rows[i].Cells["金额"].Value;
        //                doc.Range.Bookmarks["备注" + nowi].Text = dataGridView2.Rows[i].Cells["备注"].Value.ToString();
        //                //order明细[i].备注 = dataGridView2.Rows[i].Cells["备注"].Value.ToString();


        //            }

        //            if (doc.Range.Bookmarks["总金额"] != null) doc.Range.Bookmarks["总金额"].Text = double.Parse(order_info.应收).ToString("F2"); ;// payall.ToString();
        //            if (doc.Range.Bookmarks["总金额中文"] != null) doc.Range.Bookmarks["总金额中文"].Text = new sales.ConvertNumToChina().ConvertSum(order_info.应收);


        //            if (doc.Range.Bookmarks["实收总金额"] != null) doc.Range.Bookmarks["实收总金额"].Text = double.Parse(order_info.实收).ToString("F2");
        //            if (doc.Range.Bookmarks["实收总金额中文"] != null) doc.Range.Bookmarks["实收总金额中文"].Text = new sales.ConvertNumToChina().ConvertSum(order_info.实收);

        //            DateTime time = DateTime.Now;
        //            string name = time.ToFileTime().ToString();
        //            string pring_path = str + "\\打印的单据-可定期删除\\" + name + "sales.doc";
        //            doc.Save(pring_path, SaveFormat.Doc); //保存为doc，并打开 
        //            doc.Clone();
        //            //str = System.Windows.Forms.Application.StartupPath;
        //            try
        //            {
        //                string strFileName = pring_path;
        //                System.Diagnostics.Process.Start(strFileName);

        //            }
        //            catch (Exception ee)
        //            {

        //            }


    }
}